import { request } from './request';

/**
 * 查询某一周的所有心率
 * @param patientUid 患者ID
 * @param params 参数 { startDate: string, endDate: string }
 */
export function getWeeklyHeartRateData(patientUid: string, params: { startDate: string; endDate: string }) {
  return request({
    url: `/patient/heartRateLogs/weekly_heart_rate_data`,
    method: 'GET',
    data: {
      patientUid,
      ...params
    }
  });
}

/**
 * 查询某一个月的所有心率
 * @param patientUid 患者ID
 * @param params 参数 { year: number, month: number }
 */
export function getMonthlyHeartRateData(patientUid: string, params: { year: number; month: number }) {
  return request({
    url: `/patient/heartRateLogs/monthly_heart_rate_data`,
    method: 'GET',
    data: {
      patientUid,
      ...params
    }
  });
}

/**
 * 查询最新的心率数据
 * @param patientUid 患者ID
 */
export function getNewlyHeartRateData(patientUid: string) {
  return request({
    url: `/patient/heartRateLogs/get_newly_heart_rate_data`,
    method: 'GET',
    data: { patientUid }
  });
}

/**
 * 查询某一天的某位患者的心率的平均值
 * @param patientUid 患者ID
 * @param date 日期 (YYYY-MM-DD)
 */
export function getDailyAvgHeartRate(patientUid: string, date: string) {
  return request({
    url: `/patient/heartRateLogs/daily_avg_heart_rate`,
    method: 'GET',
    data: { patientUid, date }
  });
}

/**
 * 查询某一周的某位患者的心率的平均值
 * @param patientUid 患者ID
 * @param params 参数 { startDate: string, endDate: string }
 */
export function getWeeklyAvgHeartRate(patientUid: string, params: { startDate: string; endDate: string }) {
  return request({
    url: `/patient/heartRateLogs/weekly_avg_heart_rate`,
    method: 'GET',
    data: {
      patientUid,
      ...params
    }
  });
}

/**
 * 查询某一个月的某位患者的每周段的心率的平均值
 * @param patientUid 患者ID
 * @param params 参数 { year: number, month: number }
 */
export function getMonthlyAvgHeartRateByWeek(patientUid: string, params: { year: number; month: number }) {
  return request({
    url: `/patient/heartRateLogs/monthly_avg_heart_rate_by_week`,
    method: 'GET',
    data: {
      patientUid,
      ...params
    }
  });
}

/**
 * 查询某一年的每个月的心率的平均值
 * @param patientUid 患者ID
 * @param year 年份
 */
export function getYearlyAvgHeartRateByMonth(patientUid: string, year: number) {
  return request({
    url: `/patient/heartRateLogs/yearly_avg_heart_rate_by_month`,
    method: 'GET',
    data: { patientUid, year }
  });
}

/**
 * 统计今天连续低心率的患者
 * @param patientUid 患者ID
 */
export function getTodayConsecutiveAbnormalities(patientUid: string) {
  return request({
    url: `/patient/heartRateLogs/todayConsecutiveAbnormalities`,
    method: 'GET',
    data: { patientUid }
  });
}

/**
 * 分页查询心率数据
 * @param patientUid 患者ID
 * @param params 分页参数 { pageNum, pageSize, sortField?, sortOrder? }
 */
export function getHeartRatePage(patientUid: string, params: { pageNum: number; pageSize: number; sortField?: string; sortOrder?: string }) {
  return request({
    url: `/patient/heartRateLogs/page`,
    method: 'GET',
    data: {
      patientUid,
      ...params
    }
  });
}
